#pragma once

#include "../ecs/ecs.hpp"
#include "../state/modeExit.hpp"
#include "qlib/core/vec2.h"
namespace qlib {
class Cell;
}
namespace qbe::tools {
struct RenderSelect;
}

typedef void (*DefMouseEevent)(double x, double y);
typedef void (*DefSelEevent)(double x, double y, std::vector<qbe::tools::RenderSelect>& sel_data);
typedef void (*DefExitFunc)(qbe::state::AllModeType enter_mode);
namespace qbe::tools {
struct TempRenderTag {};
struct PickTag {
  bool is_pick = true;
};
struct RenderSelect {
  entt::entity sel_entitys;
  std::vector<int> select_indexs;
  std::vector<qlib::Vec2d> key_points;
  void reset() {
    sel_entitys = entt::null;
    select_indexs.clear();
    key_points.clear();
  }
};

struct SelectedAndPreSelected {
  std::vector<RenderSelect> selected;
  std::vector<RenderSelect> pre_selected;
};
class InterfaceObjcet {
 public:
  DefMouseEevent mouse_left_press = nullptr;
  DefMouseEevent mouse_left_release = nullptr;
  DefMouseEevent mouse_left_drag = nullptr;
  DefMouseEevent mouse_right_press = nullptr;
  DefMouseEevent mouse_right_release = nullptr;
  DefMouseEevent mouse_move = nullptr;

  DefSelEevent select_event = nullptr;
  DefSelEevent pre_select_event = nullptr;

  DefExitFunc exit = nullptr;
  std::function<void(std::vector<entt::entity>&, std::vector<entt::entity>&, std::vector<entt::entity>&)> recordUndoRedoDataEnd;
};

void addOperator(ecs::Query query, ecs::Bus& bus, std::vector<std::any> add_graphs, std::vector<entt::entity> delete_graphs,
                 std::vector<std::shared_ptr<qlib::Cell>> new_cells);
class ToolsInterfacePlugin : public ecs::Plugin {
 public:
  void build(ecs::App& app) override;
};

}  // namespace qbe::tools